﻿@{
    ViewBag.Title = "工伤事故台账月报";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <script src="~/Areas/Mms/ViewModels/mms.com.js"></script>
    <script src="~/Areas/Mms/ViewModels/mms.viewModel.search.js"></script>
    <script type="text/javascript">
            function resizeColumn(value,row,index)
            {
                return "white-space:normal";
            }
            var data = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
            var viewModel = function(){ 
                var self = this;
                this.form = ko.mapping.fromJS(data.form);
                mms.viewModel.search.apply(this,arguments);
                self.getSize = function(){
                    var size = {w:4,h:94},ret = {};
                    if (size && size.w) ret.width = $(window).width() - size.w;
                    if (size && size.h) ret.height = $(window).height() - size.h;
                    return ret;
                },
                self.grid = {
                    width:self.getSize().width,
                    height:self.getSize().height,
                    idField:'Gssgtz_Sgyy',
                    queryParams:{},
                    onDblClickRow: $.noop,
                    iconCls: 'icon icon-list',
                    nowrap: true,           //折行
                    rownumbers: true,       //行号
                    striped: true,          //隔行变色
                    singleSelect: true,     //单选
                    remoteSort: true,       //后台排序
                    pagination: true,      //翻页
                    pageSize: com.getSetting("gridrows",20),
                    onSortColumn : function (sort, order) { 
                        self.grid.queryParams = $.extend(self.grid.queryParams,{sort: sort, order: order });
                        com.ajax({
                            type: 'get',
                            url: '/api/senv/Gssgtz/GetTjcxMonthly/',
                            data: ko.toJS(self.grid.queryParams),
                            success: function (d) {
                                $('#gridlist').datagrid('loadData', { total: d.total, rows: d.rows });
                            }
                        });
                    }
//                     frozenColumns:[[
//                            {field:'Gssgtz_Sgyy',title:'事故原因',width:100, rowspan:2,sortable:true}
//                    ]]
                };

                self.searchClick=function(){
                    com.ajax({
                        type: 'get',
                        url: '/api/senv/Gssgtz/GetTjcxMonthly/',
                        data: $.extend(self.grid.queryParams,{page:1,rows:self.grid.pageSize}, self.form),
                        success: function (d) {
                            self.grid.columns  = JSON.parse(d.Title);
                            $("#gridlist").datagrid(self.grid).datagrid('loadData', d.rows);
                            $("#gridlist").datagrid('resize',self.getSize());
                            $("#gridlist").datagrid('getPager').pagination({ onSelectPage: function(pageindex, pagenumber){
                                self.grid.queryParams = $.extend(self.grid.queryParams,{page:pageindex,rows:pagenumber});
                                com.ajax({
                                    type: 'get',
                                    url: '/api/senv/Gssgtz/GetTjcxMonthly/',
                                    data: self.grid.queryParams,
                                    success: function (d) {
                                     $('#gridlist').datagrid('loadData', { total: d.total, rows: d.rows });
                                    }
                                });
                            } });
                        }
                    });
                };
                using('datagrid',function(){
                    self.searchClick();
                });
                self.downloadClick = function (vm, event) {
                    var titles = [[]],length = self.grid.columns.length;
                    for(var i=0;i<length;i++)
                        titles[i] = self.grid.columns[i];

                    var opt = {
                        dataGetter:"api",
                        dataAction:"/api/senv/Gssgtz/GetTjcxMonthly/",
                        titles: titles,
                        dataParams: self.grid.queryParams
                    };
                    com.exporter(opt).download($(event.currentTarget).attr("suffix"));
                };
            };
            ko.bindingViewModel(new viewModel(data));
    </script>
}
<div class="z-toolbar">
    <a id="a_refresh" href="#" plain="true" class="easyui-linkbutton" icon="icon-arrow_refresh"
        title="刷新" data-bind="click:refreshClick">刷新</a> <a id="a_export" href="#" class="easyui-splitbutton"
            data-options="menu:'#dropdown',iconCls:'icon-download'">导出</a>
</div>
<div id="dropdown" style="width: 100px; display: none;">
    <div data-options="iconCls:'icon-ext-xls'" suffix="xls" data-bind="click:downloadClick">
        Excel2003
    </div>
    <div data-options="iconCls:'icon-page_excel'" suffix="xlsx" data-bind="click:downloadClick">
        Excel2007
    </div>
    <div data-options="iconCls:'icon-ext-doc'" suffix="doc" data-bind="click:downloadClick">
        Word2003
    </div>
</div>
<div id="condition" class="container_12" style="position: relative;">
    <div class="grid_1 lbl">
        单位名称</div>
    <div class="grid_2 val">
        <input type="text" data-bind="value:form.Gssgtz_Dwmc" class="z-txt easyui-autocomplete"
            data-options="url:'/api/mms/merchant/getnames'" /></div>
    <div class="clear">
    </div>
    <div class="grid_1 lbl">
        发生日期</div>
    <div class="grid_2 val">
        <input type="text" data-bind="value:form.Gssgtz_Fsrq" class="z-txt easyui-daterange" /></div>
    <div class="clear">
    </div>
    <div class="prefix_9" style="position: absolute; top: 5px; height: 0;">
        <a id="a_search" href="#" class="button button-blue" style="margin: 0 15px;" data-bind="click:searchClick">
            查询</a> <a id="a_reset" href="#" class="button button-blue" data-bind="click:clearClick">
                清空</a>
    </div>
</div>
<table id="gridlist" data-bind1="datagrid:grid">
</table>
